/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */
import  { Tooltip } from 'view-design'

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 20,
  currentPage: 1
};

//页面状态相关
let status = {
  modalEmail: {
    isShow: false,
    isLoading: false,
    hasName : false
  },
  modalopRecord: {
    isShow: false,
    isLoading: false
  },
  modalCustomerInfo: {
    isShow: false,
  },
  ruleCustomer: {
    contactUrl:{type: 'url', message: '站内信地址不正确', trigger: 'blur'},
    externalEmail: [
      {type: 'email', message: '邮箱格式不正确', trigger: 'blur'},
      {type: 'string', max: 200, message: '邮箱最长不能超过200个字符', trigger: 'blur'}
    ],
  },


  modalAssign:{
    isShow : false,
    isLoading : false
  },
  modalTag:{
    isShow:false
  },
  modalContact:{
    isShow : false,
    isLoading : false
  },
  modalSearchTag:{
    isShow : false,
    type:1,//标签类型
    tagData:[],
    selectedTags:[],
    selectedOtherTags:[]
  }
};

// 和网络交互相关的参数
let params = {
  searchInfo: {
    state: 120,
    customerName: "",
    number: "",
    isHasShop:false,
    startTime:"",
    endTime:"",
    orderBy:"",
    tags:"",
    otherTags:""
  },
  customerInfo: {
    id: "",
    customerName: "",
    contactUrl:"",
    externalEmail: "",
    customerDesc: "",
    isSendLetter: false,
    state: 0,
    externalUrl:'', //个人主页
   extendInfo:{
      followerCount:0,//粉丝数
      followingCount:0,//关注数
      description:'',
      alexa:0,	//网站排名
      country:'',	//网站国家编码
      title:'',	//网站标题
      siteDesc:'',//原网站描述
      extra:'',//网站扩展信息
      facebook:'',
      twitter:'',
      instagram:'',
      pinterest:''
    },
    tags:[],//可维护标签
    readonlyTags:[],//抓取到的网站标签
    otherTags:[],//其他标签
    contacts:[],
    opRecords:[]
  },
  contact:{
    "customerId":'',
    "country":'',
    "countryCode":'',
    "address":'',
    "phone":'',
    "postalCode":'',
    "sequence":0,
    index:-1
  },
  changeStateCustomerInfo: {
    id: "",
    number:""
  },
  opRecordSave: {
    customerName: "",
    customerId: "",
    customerOperation: 0,
    operationDesc: "",
    operationTime: ""
  },
  opRecordQuery: {
    customerId: "",
    customerName: ""
  },
  batchCustomer: {
    customerIds: [],
    state: 300
  },
  selectedCustomers: [],
  selectedEmployee:{},
  selectedTags:[],
  selectedOtherTags:[]

};

// 页面的数据源
let data = {
  userList: [],
  opRecordList: [],
  customerInfo: {},
  employeeList :[],
};

let customerFilterOperation = function (self) {

  return self.$store.getters.dictionaries.customerOperation.filter(item => item.value > 500);
}

let tableTitles = function (self) {
  return [
    {
      type: 'selection',
      align: 'center',
      fixed: 'left',
      width: 60
    },
    {
      type: 'index',
      title: '#',
      width: 70,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    // {
    //   title: '用户名',
    //   width: 180,
    //   key: 'name',
    //   align:'center',
    //   render: (h, params) => {
    //     let hasAuth = self.$authority("OPERATIONS-3-201");
    //     let userName = params.row.name? params.row.name :"";
    //     let hideName = Vue.prototype.$tiyHideUsername(userName);
    //     if (!hasAuth){
    //       return (
    //         <div>
    //           <Tooltip content={userName} placement="top">
    //             {hideName}
    //           </Tooltip>
    //         </div>
    //       );
    //     } else{
    //       return (
    //         <div>
    //           <Tooltip content={userName} placement="top">
    //             <a style="padding:6px;font-size:13px" onClick={() => {self.getCustomerDetail(params.row.id, params.row.state);}}>
    //               {hideName}
    //             </a>
    //           </Tooltip>
    //         </div>
    //       );
    //     };
    //   }
    // },
    {
      title: '独立站编号',
      width: 180,
      key: 'number',
      align:'center',
      render: (h, params) => {
        let hasAuth = self.$authority("OPERATIONS-2-201");
        if (!hasAuth){
          return (<div>{params.row.number}</div>);
        } else{
          return (
            <div>
              <a onClick={() => {self.getCustomerDetail(params.row.id, params.row.state);}}>{params.row.number}</a>
            </div>
          );
        };
      }
    },
    {
      title: '独立站',
      key: 'externalUrl',
      width: 100,
      align:'center',
      render: (h, params) => {
        let externalUrl = params.row.externalUrl;
        if (!externalUrl){
          return (
            <div><span></span></div>
        );
        }else{
          return (
            <div>
            <Tooltip content={externalUrl} placement="top">
            <a target='_blank' href={externalUrl}> 点击访问 </a>
            </Tooltip>
            </div>
        );
        }
      }
    },
    {
      title: '站内信',
      key: 'contactUrl',
      width: 100,
      align:'center',
      render: (h, params) => {
        return params.row.contactUrl ? h("div", [h('a', {
          attrs: {
            target: "_blank", href: params.row.contactUrl
          }
        }, "站内信")]) : h("div", "");
      }
    },

    {
      title: '状态',
      width: 130,
      key: 'state',
      align:'center',
      render: (h, params) => {
        let color = 'green';
        if (params.row.state===300){
          color = "red";
        }
        if (params.row.state===500){
          color = "blue";
        }
        if (params.row.state===120){
          color = "default";
        }

        return h('Tag',{
          attrs:{color:color}
        }, self.filterStateList.filter(item => item.value === params.row.state)[0].name);
      }
    },
    {
      title: '邮箱',
      width: 90,
      key: 'externalEmail',
      align:'center',
      render: (h, params) => {
        if (!params.row.externalEmail) {
          return h("div", "无");
        } else {
          return h("div", "有邮箱");
        }
      }
    },
    {
      title: '国家',
      width: 70,
      key: 'country',
      align:'center',
      render: (h, params) => {
        return params.row.country ? (<div>{params.row.country}</div>) : (<div></div>);
      }
    },

    // {
    //   title: '导入时间',
    //   minWidth: 150,
    //   key: 'createtime',
    //   sortable: 'custom',
    //   align:'center',
    //   render: (h, params) => {
    //     let date = new Date(params.row.createtime);
    //   }
    // },
    {
      title:'信息采集',
      align:"center",
      width:100,
      render: (h, params) => {
        return h('div',[
          h('Button', {
            props: {type: 'info', size: 'small', icon: ""},
            style: {
              marginRight: '10px', marginTop: '6px', marginBottom: '3px'
              // display: (params.row.state == 200 && self.$authority("OPERATIONS-3-204")) ? 'inline-block' : 'none'
            },
            on: {
              click: () => {
                self.setExternalEmailShow(params.row.id, params.row.state)
              }
            }
          }, '采集')
        ])
      }
    },

    {
      title: '操作',
      minWidth: 100,
      // fixed: 'right',
      align:'center',
      key: 'operation',
      render: (h, params) => {
        return h('div', [h('Button', {
          props: {type: 'primary', size: 'small', icon: ""},
          style: {
            marginRight: '10px',  marginTop: '6px', marginBottom: '3px',
            display: (params.row.state == 120 && self.$authority("OPERATIONS-3-203"))? 'inline-block' : 'none'
          },
          on: {
            click: () => {
              self.setEffective(params.index);
            }
          }
        }, '有效'),
          h('Button', {
            props: {type: 'error', size: 'small', icon: ""},
            style: {
              marginRight: '16px', marginTop: '6px', marginBottom: '3px',
              display: (params.row.state == 120 && self.$authority("OPERATIONS-3-202")) ? 'inline-block' : 'none'
            },
            on: {
              click: () => {
                self.setStateInvalid(params.index);
              }
            }
          }, '无效'),
          h('Button', {
            props: {type: 'warning', size: 'small', icon: ""},
            style: {
              marginRight: '10px', marginTop: '6px', marginBottom: '3px',
              display: ( params.row.state > 310 && self.$authority("OPERATIONS-3-205")) ? 'inline-block' : 'none'
            },
            on: {
              click: () => {
                self.opRecordShow(params.index)
              }
            }
          }, '操作记录'),
        ])
      }
    }
  ];
};
// let tableTitles1 = function (self) {
//   return [
    // {
    //   title: '国家',
    //   width: 80,
    //   key: 'country',
    //   align:'center',
    //   render: (h, params) => {
    //     return params.row.country ? (<div>{params.row.country}</div>) : (<div></div>);
    //   }
    // },
    // {
    //   title: '邮编',
    //   width: 80,
    //   key: 'country',
    //   align:'center',
    //   render: (h, params) => {
    //     return params.row.country ? (<div>{params.row.country}</div>) : (<div></div>);
    //   }
    // },
    // {
    //   title: '电话',
    //   width: 80,
    //   key: 'country',
    //   align:'center',
    //   render: (h, params) => {
    //     return params.row.country ? (<div>{params.row.country}</div>) : (<div></div>);
    //   }
    // },

    // ];
let role = {};


export default {
  tStatus: status,
  tParams: params,
  tData: data,
  tPage: page,
  tableTitles: tableTitles,
  customerFilterOperation: customerFilterOperation
};
